Conversation
MyNUnit/AttributesMyNunit/After.cs
Outdated
| using System; | ||
|
|
||
| /// <summary> | ||
| /// Атрибут, которым обозначают методы, которые вызываются после каждого тестом |
There was a problem hiding this comment.
| /// Атрибут, которым обозначают методы, которые вызываются после каждого тестом | |
| /// Атрибут, которым обозначают методы, которые вызываются после каждого теста |
MyNUnit/AttributesMyNunit/After.cs
Outdated
| public After() | ||
| { | ||
|
|
||
| } |
There was a problem hiding this comment.
Вообще, пустой конструктор сгенерируется и так, можно не писать.
MyNUnit/AttributesMyNunit/Test.cs
Outdated
|
|
||
| public string Ignore { get; set; } | ||
|
|
||
| public Test(Type expected, string ignore = null) |
There was a problem hiding this comment.
Компилятор огорчён происходящим
MyNUnit/MyNUnit.Test/MyNUnit.Test.cs
Outdated
|
|
||
| public class Tests | ||
| { | ||
| private readonly MyNUnit myNUnit = new MyNUnit(); |
There was a problem hiding this comment.
| private readonly MyNUnit myNUnit = new MyNUnit(); | |
| private readonly MyNUnit myNUnit = new (); |
MyNUnit/MyNUnit/MyNUnit.cs
Outdated
| var dlls = Directory.GetFiles(path, "*.dll"); | ||
| var tasks = new Task<List<(string, string)>>[dlls.Length]; | ||
| var message = new List<(string, string)>(); | ||
| Parallel.ForEach(dlls,dll => DoTestFromDll(dll, message)); |
There was a problem hiding this comment.
| Parallel.ForEach(dlls,dll => DoTestFromDll(dll, message)); | |
| Parallel.ForEach(dlls, dll => DoTestFromDll(dll, message)); |
MyNUnit/MyNUnit/MyNUnit.cs
Outdated
| return; | ||
| } | ||
| object classInstance = Activator.CreateInstance(classDll); | ||
| Parallel.ForEach(before, method => RunMethodsWithAttributes(method, messagesFromCurrentTest, classInstance)); |
There was a problem hiding this comment.
То же с Before — если их много, могут быть гонки в пользовательском коде. Так что либо запрещать, чтобы их было много, либо исполнять последовательно
MyNUnit/MyNUnit/MyNUnit.cs
Outdated
| } | ||
| else | ||
| { | ||
| message = ($"Тест {test.Name} не пройден: ожидалось исключения типа {attribute.Expected}", $"Время: {watch.ElapsedMilliseconds} ms"); |
There was a problem hiding this comment.
| message = ($"Тест {test.Name} не пройден: ожидалось исключения типа {attribute.Expected}", $"Время: {watch.ElapsedMilliseconds} ms"); | |
| message = ($"Тест {test.Name} не пройден: ожидалось исключение типа {attribute.Expected}", $"Время: {watch.ElapsedMilliseconds} ms"); |
MyNUnit/MyNUnit/MyNUnit.cs
Outdated
| } | ||
| else if (exception.InnerException.GetType() != attribute.Expected) | ||
| { | ||
| message = ($"Тест {test.Name} не пройден: ожидалось исключения типа {attribute.Expected}, возникло {exception.InnerException.GetType()}", $"Время: {watch.ElapsedMilliseconds} ms"); |
There was a problem hiding this comment.
| message = ($"Тест {test.Name} не пройден: ожидалось исключения типа {attribute.Expected}, возникло {exception.InnerException.GetType()}", $"Время: {watch.ElapsedMilliseconds} ms"); | |
| message = ($"Тест {test.Name} не пройден: ожидалось исключение типа {attribute.Expected}, возникло {exception.InnerException.GetType()}", $"Время: {watch.ElapsedMilliseconds} ms"); |
MyNUnit/MyNUnit/MyNUnit.cs
Outdated
| private int CheckAttributesInMethod(Attribute[] attribute) | ||
| { | ||
| if (attribute.Length > 0) | ||
| { | ||
| return 1; | ||
| } | ||
|
|
||
| return 0; | ||
| } |
There was a problem hiding this comment.
| private int CheckAttributesInMethod(Attribute[] attribute) | |
| { | |
| if (attribute.Length > 0) | |
| { | |
| return 1; | |
| } | |
| return 0; | |
| } | |
| private int CheckAttributesInMethod(Attribute[] attribute) | |
| => attribute.Length > 0 ? 1 : 0; |
MyNUnit/MyNUnit/MyNUnit.cs
Outdated
| return 0; | ||
| } | ||
|
|
||
| private void RunMethodsWithAttributes(MethodInfo method, List<(string, string)> messagesForUser, object ClassIntstase) |
There was a problem hiding this comment.
| private void RunMethodsWithAttributes(MethodInfo method, List<(string, string)> messagesForUser, object ClassIntstase) | |
| private void RunMethodsWithAttributes(MethodInfo method, List<(string, string)> messagesForUser, object classInstance) |
yurii-litvinov
left a comment
There was a problem hiding this comment.
Всё ещё несколько предупреждений "Cannot convert null literal to non-nullable reference type." при компиляции. А должно компилироваться без предупреждений.
| /// </summary> | ||
| /// <param name="path">путь до .dll</param> | ||
| /// <returns>Кортеж из (названия теста, результат о нем)</returns> | ||
| public (string, string)[] RunTests(string path) |
There was a problem hiding this comment.
Интересно, почему именно массив и зачем ToArray в конце
| return count; | ||
| } | ||
|
|
||
| private void GetAttributesAndDoBeforeAndAfterClass(MethodInfo method, TestAttributes testAttributes) |
There was a problem hiding this comment.
Название метода всё ещё неправдиво.
| /// </summary> | ||
| public class MyNUnit | ||
| { | ||
| private ConcurrentBag<(string, string)> messages; |
There was a problem hiding this comment.
ConcurrentBag — это неупорядоченное множество. Сообщения могут произвольно перемешиваться, что, наверное, не то, что хотелось.
| { | ||
| return; | ||
| } | ||
| messages.Add(($"Проверка тестов из {classFromDll.Name}", "")); |
There was a problem hiding this comment.
Выше написано, что messages --- это Кортеж из (названия теста, результат о нем). Тут (и везде, где используется messages) что-то не то написано, либо комментарий неправдив.
| } | ||
| } | ||
|
|
||
| private void RunMethodsWithAttributes(List<MethodInfo> methods, object classIntstase) |
There was a problem hiding this comment.
| private void RunMethodsWithAttributes(List<MethodInfo> methods, object classIntstase) | |
| private void RunMethodsWithAttributes(List<MethodInfo> methods, object classInstance) |
| } | ||
| } | ||
|
|
||
| private void RunMethodsWithAttributes(List<MethodInfo> methods, object classIntstase) |
There was a problem hiding this comment.
Тоже неправдивое название, кстати. Этот метод буквально ничего не делает касательно атрибутов.
| var types = new Type[] { typeof(Before), typeof(BeforeClass), typeof(Test), typeof(AfterClass), typeof(After)}; | ||
| var typesCount = new Attribute[5][]; | ||
| for (int i = 0; i < types.Length; i++) | ||
| { | ||
| typesCount[i] = Attribute.GetCustomAttributes(method).Where(t => t.GetType() == types[i]).ToArray(); | ||
| } | ||
| return typesCount; |
There was a problem hiding this comment.
Самодельный IEnumerable.GroupBy :)
| private int GetSumOfAttributesInMethod(Attribute[][] array) | ||
| { | ||
| var count = 0; | ||
| for (int i = 0;i < array.Length;i++) |
There was a problem hiding this comment.
| for (int i = 0;i < array.Length;i++) | |
| for (int i = 0; i < array.Length; i++) |
| } | ||
| private class TestAttributes |
There was a problem hiding this comment.
| } | |
| private class TestAttributes | |
| } | |
| private class TestAttributes |
No description provided.